<template>
  <div class="detail" v-if="activeName === 'first'">
    <div class="title">{{messageData.title}}</div>
    <div class="time">发布时间：{{messageData.time}}</div>
    <div class="content" v-html="messageData.content"></div>
  </div>
  <div class="detail" v-else>
    <div class="title">{{policyData.title}}</div>
    <div class="time">发布时间：{{policyData.time}}</div>
    <div class="content w-e-text-container" v-html="policyData.content"></div>
  </div>
</template>

<script setup lang="ts" name="newsDetail">
import { onMounted,ref } from 'vue';
import { reqMessageInfoById } from '@/api/message';
import { reqPolicyInfoById } from '@/api/policy';
import { useRouter, useRoute } from "vue-router";

//获取路由器对象
let $router = useRouter();
let $route = useRoute();

let activeName = $route.query.current
// id
let id = $route.query.id
// 资讯数据
let messageData = ref<any>({})
// 首页政策数据
let policyData = ref<any>({})

// 根据id获取资讯数据
const getMessgeInfo = async () => {
  let result = await reqMessageInfoById(id)
  if (result.code == 200) {
    messageData.value = result.data;
  }
};

// 根据id获取政策数据
const getPolicyInfo = async () => {
  let result = await reqPolicyInfoById(id)
  if (result.code == 200) {
    policyData.value = result.data;
  }
};

onMounted(() => {
    if (activeName === "first") {
    getMessgeInfo();
  } else {
    getPolicyInfo();
  }
})
</script>

<style lang="scss" scoped>
.detail {
  width: 1200px;
  min-height: 480px;
  margin: 0 auto;
  background: #fff;
  padding: 30px;
  .title {
    font-size: 20px;
    font-weight: 600;
    text-align: center;
    margin-bottom: 20px;
  }
  .time {
    color: #999;
    padding-bottom: 20px;
    border-bottom: 1px solid #eee;
    font-size: 14px;
  }
  .content {
    margin-top: 20px;
    font-size: 16px;
    line-height: 20px;
  }
}
</style>
